package user

import (
	"APi/client"
	"APi/request"
	"APi/response"
	"github.com/gin-gonic/gin"
	user "user_srv/proto"
)

func CouponAdd(c *gin.Context) {
	userId := c.GetUint("userId")
	var data request.CouponAddRequest
	if err := c.ShouldBind(&data); err != nil {
		response.CurrencyErrResponse(c, 101, err.Error())
		return
	}
	res, err := client.CouponAdd(c, &user.CouponAddRequest{
		Userid:   int64(userId),
		CouponId: int64(data.CouponId),
	})
	if err != nil {
		response.CurrencyErrResponse(c, -1, err.Error())
		return
	}
	if !res.Success {
		response.CurrencyErrResponse(c, -1, "系统繁忙,领取优惠券失败")
		return
	}
	response.CurrencySuccessResponse(c, "优惠券领取成功", nil)
}
